package SingletonPattern;

public class SingletonLazy {
    private static volatile SingletonLazy singleton = null;
    //私有的构造方法
    private SingletonLazy(){

    }
    //获取实例对象的方法，变量不为 null 的时候直接返回该实例对象
    public static SingletonLazy getInstance(){
        if (singleton == null){
            synchronized (SingletonLazy.class){
                if (singleton == null){
                    singleton = new SingletonLazy();
                }
            }
        }
        return singleton;
    }
    //其他方法
    public void fun(){
        System.out.println("懒汉单例模式");
    }
}
